<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5.4.2/themes/icon.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css"/>
<script type="text/javascript"
	src="<c:url value="/js/common.js"/>"></script>
</head>
<body>
<script type="text/javascript">

		function editcontact(contId){
			$("#lwc-win-contact-add").dialog({href2:"editContact/"+contId,title:"编辑联系人信息"});
				
			$("#lwc_contact_insert").form('load', 'getContactById/' + contId);
			$("#lwc-win-contact-add").dialog("open");	
		}

		function Detailscontact(contId){
	
		}

		function deletecontact(contId){
			
			$.messager.confirm('提示', '确定要删除吗？本数据视图下存在关联数据可能会被删除的！', function(v){
				if(v){
					
					$.getJSON("delOneContact", {contId:contId}, function(data){
						if(data){
							$("#lwc_contact_table").datagrid("load");
						}else{
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
						}
					});

				}
			});
		}
		$(function() {
			
/* 			//导出数据
			$("#lwc_informationFinancial_tb_export").linkbutton({onClick:function(){
				var code = $("#lwc_tocontactclassify_cb").combobox('getValue');
				var value = $("#lwc_tocontactclassify_mm_sb").searchbox('getValue');
				$("#lwc_informationFinancial_export_dlg").dialog({title: '数据导出'});
				$("#lwc_informationFinancial_export_dlg").dialog("open");
				var options = $('#lwc_contact_table').datagrid('getPager').data("pagination").options;  
				var page = options.pageNumber;//当前页数
				var total = options.total;  
				var max = Math.ceil(total/options.pageSize);  
				var rows = options.pageSize;//每页的记录数（行数）  
				
				if(code=='全部数据'){
					$("#markcode").val('0');
				}else{
					$("#markcode").val(code);
				}
				$("#value").val(value);
				$("#page").val(page);
				$("#total").val(total);
				$("#rows").val(rows);
				//alert(page+" "+rows+" "+max);
			}});
			$('#lwc_tocontactclassify_cb').combobox({onChange:function(n,o){
				
				//暂未解释
				$('#lwc_tocontactclassify_mm_sb').searchbox('reset');
				var l = $('#lwc_tocontactclassify_cb').combobox('getValue');
				if(l==1){
					$('#lwc_contact_table').datagrid('load','toQuerycontact?markcode=1');
				}else if(l==2){
					$('#lwc_contact_table').datagrid('load','toQuerycontact?markcode=2');
				}else if(l==3){
					$('#lwc_contact_table').datagrid('load','toQuerycontact?markcode=3');	
				}else if(l==4){
					$('#lwc_contact_table').datagrid('load','toQuerycontact?markcode=4');
				}else if(l==5){
					$('#lwc_contact_table').datagrid('load','toQuerycontact?markcode=5');
				}else if(l==6){
					$('#lwc_contact_table').datagrid('load','toQuerycontact?markcode=6');
				}else if(l==7){
					$('#lwc_contact_table').datagrid('load','toQuerycontact?markcode=7');
				}	
			}}); */
			
				//编辑
				$("#lwc-contact-add-ok").linkbutton({onClick:function(){
				
					var row = $("#lwc_contact_table").datagrid("getSelected");
					
					$("#lwc_contact_insert").form({
						url: $('#lwc-win-contact-add').dialog('options').href2,
						method:"post",
						onSubmit:function(params){
							if(row != null){
								params.contId = row.contId;
							}
							return $(this).form('validate');
						},
						success:function(v){
							var obj = eval('(' + v + ')');
							if(obj.success){
								$('#lwc_contact_table').datagrid('reload');

							}else{
								$.messager.alert('提示', '操作失败, 原因：' + obj.message);
							}
							$("#lwc-win-contact-add").window("close");
						}
					}).submit();
				}}); 
				//添加
				$("#lwc_btn_contact_add").linkbutton({
					onClick : function() {
						
						$("#lwc-win-contact-add").dialog({href2:"addNewContact",title:"新建联系人"});
						
						$("#lwc_contact_insert").form("clear");
						
						$("#lwc-win-contact-add").dialog("open");
					
					}
				});

				//刷新
				$("#lwc_contact_list_all").linkbutton({
					onClick : function() {
						$('#lwc_contact_table').datagrid({
							pageNumber : 1,
							url : 'getlistContact'
						});
						$("lwc_contact_table").datagrid("reload");
					}
				});
				
				//批量删除
				$("#lwc_contact_list_deletemore").linkbutton({
					onClick:function(){
						var selRow = $("#lwc_contact_table").datagrid('getSelections');	
						if(selRow.length == 0){
							$.messager.alert('温馨提示','请至少选择一行数据！');
							return false;
						}
						
						var ids=[];
						for (var i = 0; i < selRow.length; i++) {  
							var id=selRow[i].contId;
							ids.push(id);
					    } 
						$.messager.confirm("温馨提示","是否确认删除？本数据视图下存在关联数据可能会被删除的！",function(r){
							if(r){
								$.getJSON("delManyContacts",{"ids[]":ids},function(data){
									if(data){
										$.messager.alert("温馨提示","删除成功！");
										$("#lwc_contact_table").datagrid("load");
									}else{
										$.messager.alert("温馨提示","删除失败！本数据视图下存在关联数据！");
										
									}
								})
							}
						}); 

					}
				});
				
				
 		//显示数据
		$("#lwc_contact_table").datagrid({
			fit:true,
			toolbar:'#lwc-contact-function-tb',
			border:false,
			fitColumns:true,
			url:'getlistContact',
			method:'get',
			singleSelect:false,
			pagination:true,
			columns:[[     
            {field:'xx',title:'',width:1,checkbox:true},
	        {field:'contId',title:'编号',width:1},    
	        {field:'contImg',title:'照片',width:1},  
	        {field:'contName',title:'联系人名称',width:1},      
	        {field:'contKinds',title:'联系人类型',width:1,formatter: function(value,row,index){ if(value==1){return '非常重要';}
	       							 if(value==2){return '重要';}
	       							 if(value==3){return '普通';}
	        						 if(value==4){return '不重要';}
         							 if(value==5){return '失效';}}},       
	        {field:'contEmail',title:'邮箱地址',width:1},   
	        {field:'custName',title:'对应客户名称',width:1},    
	        {field:'contPhone',title:'联系电话',width:1},    
	        {field:'bb',width:4,title:'操作', formatter:function(value, row, index){ 
	                var btn = '<a class="lwc-contact-edit" onclick="editcontact('+row.contId+')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
	                var btn2 = '<a class="lwc-contact-delete" onclick="deletecontact('+row.contId+')" href="javascript:void(0)" class="easyui-linkbutton"></a>'; 

	                return btn+btn2;  
	            }  
	        }  
	    ]],  
	    onLoadSuccess:function(data){  
	        $('.lwc-contact-edit').linkbutton({text:'编辑',plain:true,iconCls:'icon-edit'});  
	        $('.lwc-contact-delete').linkbutton({text:'删除',plain:true,iconCls:'icon-cut'}); 
	      
	    }  
		});		
				
				
				
		
	})
				
		
</script>
<style>
.sep{
margin-top:15px;
margin-left:10px;
}
#lwc_contact_insert{

}
</style>


    <!-- 数据表格 -->
	<table id="lwc_contact_table" class="easyui-datagrid">
	</table>	
	<!-- 功能按钮 -->
	<div id="lwc-contact-function-tb">
			<a id="lwc_btn_contact_add" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新建</a>
	        <a id="lwc_contact_list_all" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
	        <a id="lwc_contact_list_deletemore" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">批量删除</a>
	        <a id="lwc_informationFinancial_tb_export" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">导出数据</a>
	        <input class="easyui-searchbox" style="width:200px;" data-options="menu:'#mm3',prompt:'联系人名称',
        		  searcher:function(value,name){
				$('#lwc_contact_table').datagrid({pageNumber:1, url: 'getContactByCnamewhere'});
				$('#lwc_contact_table').datagrid('load', {key: value});}" />
						 <div id="mm3" style="width:150px">
							  <div data-options="name:'item1',selected:true">联系人名称</div>			
							  <div data-options="name:'item2'">客户名称</div>				  
						</div>   
    </div>
      <!-- 添加窗口 -->
    <div id="lwc-win-contact-add" class="easyui-dialog" style="width:800px; height: 500px; padding: 10px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
		<!--窗口布局  -->		
		<div class="easyui-layout" data-options="fit:true">
		  	<div data-options="region:'center'" style="padding:10px;">
		   		<form id="lwc_contact_insert" name="contactForm" method="post">
					<div class="sep"><input class="easyui-textbox" data-options="required:true,label:'姓名',prompt:'联系人姓名',width:400, labelWidth:80" name="contName"></div>
					
					<div class="sep"><input class="easyui-textbox" data-options="label:'电话',width:220, labelWidth:80" name="contPhone"></div>
					<div class="sep"><input id="lwc_form_customer" class="easyui-textbox" name="custName" data-options="required:true,buttonText:'客户名称', label:'客户名称', labelWidth:'80', width: 300, 
						onClickButton:function(){
							getCustomer2(function(row){
								$('#lwc_form_customer').textbox('setValue', row.custName);
							});
						}">
					</div> 				
					<div class="sep"><select class="easyui-combobox" data-options="required:false,panelHeight:'auto',label:'联系人分类',
						width:250, labelWidth:80" name="contKinds">
						<option value="1">非常重要</option>
						<option value="2">重要</option>
						<option value="3">普通</option>
						<option value="4">不重要</option>
						<option value="5">失效</option>
						</select></div>					
						<div class="sep"><input class="easyui-textbox" data-options="label:'邮箱地址',prompt:'邮箱地址',width:220, labelWidth:80" name="contEmail"></div>
						<div class="sep"><input class="easyui-textbox" data-options="label:'图片',prompt:'图片',width:400, labelWidth:80" name="contImg"></div>
				</form>
		  	</div>
		  	
		    <div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0; text-align: center;">
		     	<a id="lwc-contact-add-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">保存</a>
		     	<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" href="javascript:void(0)" onclick="javascript:$('#lwc-win-contact-add').window('close');">取消</a>
	 	   </div>
		</div>		


    </div>
    
    <div id="lwc_informationFinancial_export_dlg" class="easyui-dialog" style="width:250px;height:300px;"   
        data-options="resizable:true,modal:true,closed:true,buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					
					$('#lwc_informationFinancial_export_form').form({
					//加载路径
						url: 'wsdExportcontact',
						onSubmit:function(params){
							
						},
						success:function(v){
							
							var obj = eval('(' + v + ')');
							if(obj.success){
								$.messager.alert('提示','导出成功！');
							}else{
								$.messager.alert('提示', '操作失败, 原因：' + obj.message);
							}
							$('#lwc_informationFinancial_export_dlg').dialog('close');
							$('#lwc_informationFinancial_export_form').form('clear');
						}
					}).submit();
					
					
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$('#lwc_informationFinancial_export_dlg').dialog('close');
				}
			}]"> 
			<form id="lwc_informationFinancial_export_form" method="post">
				<table style="margin:80px 25px;">
					<tr>
						<td><input type="radio" checked name="exportcontact" value="1"></td>
						<td>导出当前页面数据</td>
					</tr>
					<tr>
						<td><input type="radio" name="exportcontact" value="2"></td>
						<td>导出所有数据</td>
					</tr>
					<input id="page" name="page" type="hidden">
					<input id="total" name="total" type="hidden">
					<input id="rows" name="rows" type="hidden">
					<input id="markcode" name="markcode" type="hidden">
					<input id="value" name="value" type="hidden">
				</table>
	    	</form> 	  
	</div>
    
</body>

</html>